package com.shen;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

/**
 * Author:shen
 * CreateDate:2020/6/1.
 * Function:
 */
public class demo01 {

    static Scanner scanner=new Scanner(System.in);
    public static void main(String[] args) {
        System.out.println("请输入一个日期字符串：");
        String date=scanner.nextLine();
        test(date);
    }
    public static boolean test(String date)  {
        boolean flag=false;
        Date getDate=null;//接收成的date数据，如果没有就输出日期格式非法
        String[] dateFormat={"yyyy/MM/dd","yyyyMMdd","yyyy-MM-dd"};
        for (String format:dateFormat){
            SimpleDateFormat simpleDateFormat=new SimpleDateFormat(format);
            try {
                getDate = simpleDateFormat.parse(date);
                System.out.println(simpleDateFormat.format(getDate));
            } catch (ParseException e) {
               continue;
            }
        }
        if(getDate==null){
            System.out.println("输入日期格式非法");
        }
        return flag;
    }
}
